home *** CD-ROM | disk | FTP | other *** search
- // REPORT.CPP - output of racing and other data to a file - M. Timin, March 1995
- // for RARS version 0.60
- // ver. 0.50 4/5/95
- // ver. 0.6b 5/8/95 b for beta
- // ver. 0.60 5/17/95
-
- #include <fstream.h>
- #include <iostream.h>
- #include <string.h>
- #include <iomanip.h>
- #include "track.h"
- #include "car.h"
- #include "os.h"
-
- ofstream fout; // fout is the output stream object (to a file)
-
- extern car_ID drivers[]; // The array of robot functions, colors & names
-
- static int how_many; // The number of cars competing
-
- int find_name(char* name) // Find this name in the drivers[] array,
- { // return its index.
- int i, cmp;
-
- for(i=0; i<MAXCARS; i++) {
- cmp = strcmp(name, drivers[i].rob_name);
- if(!cmp)
- break;
- }
- if(i == MAXCARS)
- return -1; // -1 is returned if name is not found,
- else
- return i; // else returned value will be 0 - 15
- }
-
- void print_help_file(void) // prints RARS.HLP to the screen, or if the
- { // file is not found, prints embedded text string.
- ifstream fin("rars.hlp");
- char c;
- int linecount = 0;
-
- if(!fin) {
- cout << "RARS.HLP is missing." << endl;
- }
- else
- while((c = (char)fin.get()) != EOF) {
- if(c == '\n') // a simple paging facility
- if(++linecount == LINES_PER_PAGE) {
- linecount = 0;
- cout << endl << "(any key to continue)";
- get_ch();
- cout << endl;
- }
- else
- cout << endl;
- else
- cout << c;
- }
- }
-
- // show remaining RAM:
- void RAM_report(void)
- {
- int rami = RAM_query(); // returns number of free 1 K RAM blocks
- fout << endl << rami << " K bytes of heap remained unused." << endl;
- }
-
- // outputs comma-separated list of robot's names to the output file
- void output_names(int cars, car_ID* drivers, int* order)
- {
- for(int i=0; i<cars; i++) {
- if(i < cars - 1) {
- fout << drivers[order[i]].rob_name << ", ";
- if(i == 7)
- fout << endl;
- }
- else
- fout << "and " << drivers[order[i]].rob_name << "." << endl;
- }
- fout << endl;
- }
-
- // Outputs number of cars and laps, name of track file, and the robot's names.
- // Also, the starting seed of the random variable generator.
- // Also, opens the output file, fout, using a name made from the track file.
- void report_overall(int cars, int laps, car_ID* drivers, long seed)
- {
- how_many = cars; // store the car count for later use
- int ord[MAXCARS], i;
- char string[256];
-
- // make a filename like the track name, but with the .out extension:
- strcpy(string, trackfile);
- for(i=0; string[i] != 0; i++)
- if(string[i] == '.' || string[i] == 0)
- break;
- string[i++] = '.';
- string[i++] = 'O';
- string[i++] = 'U';
- string[i++] = 'T';
- string[i] = 0;
-
- fout.open(string); // Open the output file
-
- fout << cars << " cars for " << laps << " laps. The track was ";
- fout << trackfile << ". The drivers were:" << endl;
- for(i=0; i<MAXCARS; i++)
- ord[i] = i;
- output_names(cars, drivers, ord);
- fout << "The initial RVG seed was " << seed << "." << endl;
- if(practice)
- fout << practice << " practice laps were requested." << endl;
- fout << endl;
- }
-
- // Outputs the race number, the finishing order, the average speeds,
- // fuel remaining and the accumulated points (formula one point system).
- // Also, the laps finished and damage for each car.
- void report_results(int race, int* order, car_ID* drivers, Car** pcar, int* ord)
- {
- int i, k, m, who;
- const int points[] = { 10, 6, 4, 3, 2, 1 };
- static int accum_pts[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- fout << " results of race " << race << ":" << endl;
- fout << "starting positions:" << endl;
-
- output_names(how_many, drivers, ord);
-
- // The places:
- m = how_many;
- for(i=0; i<m; i++) {
- k = order[i];
- who = find_name(drivers[k].rob_name); // Where is the kth car in the original list?
- if(i < 6)
- accum_pts[who] += points[i];
- fout << setiosflags(ios::right)<< setw(2) << (i+1) << (" ");
- fout << setw(8) << drivers[k].rob_name;
- fout << setprecision(2);
- fout << setiosflags(ios::left);
- fout << " avg spd " << setw(6) << pcar[k]->speed_avg * MPH_FPS;
- fout << setiosflags(ios::right);
- fout << " " << setw(3) << pcar[k]->laps << " laps ";
- fout << setw(5) << pcar[k]->damage << " damage ";
- fout << setw(3) << int(pcar[k]->fuel) << " fuel ";
- fout << setw(3) << accum_pts[who] << " pts accum" << endl;
- }
- fout << endl;
- }
-
- void version_report(void)
- {
- cout << "This is RARS version 0.60.";
- cout << endl;
- }
-